<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
class UserLogin extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'bail|required|email',  //|unique:users,email
            'password' => 'required'
        ];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'email.required' => '请输入邮箱',
            'email.email' => '邮箱格式不正确',
            'email.exists' => '邮箱未注册',
            'password.required' => '请输入密码'
        ];
    }

    /**
     * @param Validator $validator
     * 重写错误提示类型
     */
    protected function failedValidation(Validator $validator) {
        $error= $validator->errors()->all();
        $resultJson = app('resultJson');
        $resultJson->setMessage($this->jsonMessage)->setData($error)->errorJson();
    }
}
